﻿using System;
using System.Threading;

namespace ConsoleApp.Job.TaskFramework
{
    /// <summary>
    /// 任务执行信息委托
    /// </summary>
    /// <param name="source">来源</param>
    /// <param name="message">执行信息</param>
    /// <param name="persistence">是否持久化</param>
    public delegate void TaskLogHandler(object source, string message, bool persistence = false);
    /// <summary>
    /// 任务执行异常信息
    /// </summary>
    /// <param name="source">来源</param>
    /// <param name="exception">异常信息</param>
    /// <param name="message">执行信息</param>
    public delegate void TaskExceptionHandler(object source, Exception exception, string message, bool persistence = false);
    /// <summary>
    /// 任务处理器接口
    /// </summary>
    public interface ITask
    {
        /// <summary>
        /// 任务执行信息事件
        /// </summary>
        event TaskLogHandler TaskLog;
        /// <summary>
        /// 任务执行异常事件
        /// </summary>
        event TaskExceptionHandler TaskException;
        /// <summary>
        /// 执行任务
        /// </summary>
        void Execute();
        /// <summary>
        /// 获取任务是否正在执行
        /// </summary>
        bool IsRunning { get; }
        /// <summary>
        /// 获取或设置任务优先级
        /// </summary>
        ThreadPriority Priority { get; set; }
        /// <summary>
        /// 任务描述信息
        /// </summary>
        string Remark { get; set; }
        /// <summary>
        /// TaskCount
        /// </summary>
        int TaskCount { get; set; }
    }

    /// <summary>
    /// 任务调试入口，标记此属性的任务，将作为程序入口点
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class DebuggerAttribute : Attribute
    {

    }
}
